package com.controller;

import com.dto.PwdDTO;
import com.service.LoginServiceImpl;
import com.service.UserServiceImpl;
import com.util.Result;
import com.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

/**
 * @author linyukun
 * @date 2022/7/7 10:35
 */
@RequestMapping("user")
@RestController
public class UserController {

    @Autowired
    private LoginServiceImpl loginServiceImpl;

    @Autowired
    private UserServiceImpl userServiceImpl;

     /**
       * 修改密码
       * @author linyukun
       * @date 2022-07-07 10:36
     */
    @RequestMapping(value="/changePwd",method = RequestMethod.POST)
    public Result changePwd(HttpServletRequest request, @RequestBody PwdDTO pwdDto){
        loginServiceImpl.isLogin();
        try{
            userServiceImpl.changePwd(pwdDto);
            return ResultUtil.returnDataSuccess("1");
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }


    @RequestMapping(value="/getUserByName",method = RequestMethod.POST)
    public Result getUserByName(HttpServletRequest request, @RequestBody PwdDTO pwdDto){
        try{
            loginServiceImpl.isLogin();

            return ResultUtil.returnDataSuccess(userServiceImpl.getUserByName(pwdDto));
        }catch(Exception e){
            e.printStackTrace();
            return ResultUtil.returnFailMsg(e.getMessage());
        }
    }
}
